import request from '@/utils/request'

// 查看当前用户能够查看的常用功能菜单
export function commonMenuApi() {
  return request({
    url: `/common-menu/getCommonMenu?client=WEB`,
    method: 'get',
    jy: true
  })
}

// 当前用户查看的常用功能菜单新增与修改
export function commonMenuAddApi(data) {
  return request({
    url: `/common-menu/addOrUpdate`,
    method: 'post',
    jy: true,
    data
  })
}

// 获取已读未读通知数量
export function commonNumApi(status) {
  return request({
    url: `/app/dj/notice/countDjExamScore?status=${status}`,
    method: 'get',
    jy: true
  })
}

// 获取通知详细信息
export function commonInfoApi(name, params) {
  console.log(name)
  const urlArr = [
    {
      name: "绩效管理通知",
      url: `/jxNotification/list`
    },
    {
      name: "科研管理通知",
      url: `/jxNotification/list`
    },
    {
      name: "党费收缴通知",
      url: "/common-menu/getDjNoticeList"
    },
    {
      name: "理论测验通知",
      url: "/common-menu/getDjExamList"
    },
    {
      name: "党群活动通知",
      url: `/masses/activityNoticeList`
    },
    {
      name: "项目管理通知",
      url: "/xm/project/notice/getProjectNoticeList"
    },
  ];

  let url = '';
  const foundItem = urlArr.find(item => item.name === name);
  if (foundItem) {
    url = foundItem.url;
  }

  return request({
    url,
    method: 'get',
    params,
    jy: true
  })
}

// 当前用户某天时间的党群活动日程
export function getDailyTaskApi(daily) {
  return request({
    url: `/common-menu/getDailyTask?daily=${daily}`,
    method: 'post',
    jy: true
  })
}

// 将未读消息变为已读
export function changeStatusApi(index, data) {
  const idx = index - 1;
  const urlArr = [
    `jxNotification/edit`,
    `jxNotification/edit`,
    `app/dj/notice/${data}`,
    `app/dj/notice/${data}`,
    `app/dj/notice/${data}`,
    `xm/project/notice/${data}`
  ];

  return request({
    url: urlArr[idx],
    method: 'put',
    data,
    jy: true
  })
}


// 我的通知通知中，查看详情
export function tongSeeinfoApi(index, params) {
  if (index == 1) { // 绩效管理通知
    return request({
      url: `/jxNotification/edit`,
      method: 'put',
      data: params,
      jy: true
    })
  }
  else if (index == 2) { // 科研管理
    return request({
      url: `/jxNotification/edit`,
      method: 'put',
      data: params,
      jy: true
    })
  }
  else if (index == 3) { // 党费收缴
     return request({
      url: `/app/dj/notice/${params}?djNoticeIds=${params}`,
      method: 'put',
      jy: true
    })
  }
  else if (index == 4) { // 理论测验
    return request({
      url: `/app/dj/notice/${params}`,
      method: 'put',
      jy: true
    })
  }
  else if (index == 5) {   // 党群活动
    return request({
      url: `/masses/eventDetail`,
      method: 'get',
      params,
      jy: true
    })
  }
  else if (index == 6) { // 项目管理通知
    return request({
      url: `/xm/project/notice/${params}`,
      method: 'put',
      jy: true
    })
  }
}

// 获取活动地点
export function activityPlaceListApi() {
  return request({
    url: `/masses/chamberList`,
    method: 'get',
    jy: true
  })
}
